package leetcode.sort;

import java.util.Arrays;

/**
 * @author :songyaozhang
 * @date :Created 2021/7/14 18:17
 * @description :
 */
public class QuickSort {

    public static void main(String[] args) {
        int[] arr = {-9, 23, 0, 10, -567, 70, 70, 70};

        quickSort(arr, 0, arr.length - 1);
        System.out.println(Arrays.toString(arr));
    }

    public static void quickSort(int[] nums, int left, int right) {
        if (left >= right) return;
        int l = left;
        int r = right;
        int pivot = nums[l];
        while (l < r) {
            while (l < r && nums[r] >= pivot) r--;
            nums[l] = nums[r];
            while (l < r && nums[l] <= pivot) l++;
            nums[r] = nums[l];
        }
        nums[l] = pivot;
        quickSort(nums, left, l - 1);
        quickSort(nums, l + 1, right);
    }
}
